// Funkcija koja puni oderedjeni select element
// Argumenti:
//      o_select:   objekt kojega punimo
//      a_array:    niz iz kojega se puni
function fill_select(o_select, url_array)
{
    var i_separator, i, s_opt_text, s_opt_value;
	
    // Postavimo duljinu niza na 0
    o_select.options.length = 0;
    for(i=0; i < url_array.length; i++)
	{
        s_opt_text = url_array[i];
        s_opt_value = i;
        
        o_select.options[i] = new Option(s_opt_text, s_opt_value);      // Postavimo vrijednosti
    }
} 


function createMessageBundleTable(o_div, msgs)
{
	var strHTMLBuilder = "<table id=\"mb_table\" cellpadding=\"1\" width=\"100%\">";
	
	strHTMLBuilder += "<thead><tr><th>name</th><th>message</th></tr></thead>";

	for(key in  msgs)
	{
		strHTMLBuilder += createMessageBundlesTableRow(key, msgs[key]);		
	}

	strHTMLBuilder += "</table>";
	
	o_div.innerHTML = strHTMLBuilder;
	
	//var t = new ScrollableTable(document.getElementById('mb_table'), 100);
}




function createMessageBundlesTableRow(name, message)
{

	var strHTML = 
				"<tr>" +
					"<td align='left'>" + name + "</td>" +
					"<td align='left' width='100%' >" + message + "</td>" +
				"</tr>";
	return strHTML;

}

function createTable(o_div, msgs, translated)
{
	var strHTMLBuilder = "<table id=\"mb_table\" cellpadding=\"1\" width=\"100%\">";
	
	strHTMLBuilder += "<thead><tr><th>name</th><th>message</th></tr></thead>";
    var i = 0;
	for(key in  msgs)
	{
		strHTMLBuilder += createTableRow(key, msgs[key], translated[i]);	
		i = i + 1;	
	}

	strHTMLBuilder += "</table>";
	
	o_div.innerHTML = strHTMLBuilder;
	
	//var t = new ScrollableTable(document.getElementById('mb_table'), 100);
}




function createTableRow(name, message, translation)
{

	var strHTML = 
				"<tr>" +
					"<td align='left'>" + name + "</td>" +
					"<td align='left' width='100%' >" + message + "</td>" +
					"<td align='left' width='100%' >" + translation + "</td>" +
				"</tr>";
	return strHTML;

}

function createTranslatedTableRow(message, translation)
{

	var strHTML = 
				"<tr>" +
					"<td align='left' width='100%' >" + message + "</td>" +
					"<td align='left' width='100%' >" + translation + "</td>" +
				"</tr>";
	return strHTML;

}

function removeAllChildNodes(node) 
{
    if (node && node.parentNode && node.parentNode.replaceChild && node.cloneNode) 
    {
        node.parentNode.replaceChild(node.cloneNode(false), node);
    }
} 
function removeAllChildNodes2(node) 
{
    if (node && node.hasChildNodes && node.removeChild) 
    {
        while (node.hasChildNodes()) 
        {
            node.removeChild(node.firstChild);
        }
    }
} 


//bijelizeko: helper hacks

//carefull: The problem is that the Firefox DOM does not ignore line breaks and whitespaces while IE does.
function getFirstChildElement(elm)
{
    if (!elm.childNodes)
    {
    return;
    }
    
    var children = elm.childNodes.length;
    
    for ( var i = 0; i <= children; i++ )
    {
        if ( elm.childNodes[i].nodeType == 1 )
        {
            return elm.childNodes[i];
        }
    }

    return;
}

//carefull: The problem is that the Firefox DOM does not ignore line breaks and whitespaces while IE does.
function getLastChildElement(elm)
{
    if (!elm.childNodes)
    {
    return;
    }
    
    var children = elm.childNodes.length;
    
    for ( var i = children-1; i > 0; i-- )
    {
        if ( elm.childNodes[i].nodeType == 1 )
        {
            return elm.childNodes[i];
        }
    }

    return;
}
